package com.culture.config.common.util;

import java.util.Random;

import lombok.experimental.UtilityClass;

@UtilityClass
public class DigitGenerate {
    private static final char[] Symbol = { '!', '?' ,'$', '%' , '&' , '*' , '(' ,')','_', '+', '=', '{', '[', '}', ']' , '@' , '#' };
    private static final char[] Number = {'1','2','3','4','5','6','7','8','9','0'};
    private static final char[] Lowercase = {'a','b','c','d','e','f','g','h','i','j','k','l','m','n','o','p','q','r','s','t','u','v','w','x','y','z'};
    private static final char[] Capitalization = {'A','B','C','D','E','F','G','H','I','J','K','L','M','N','O','P','Q','R','S','T','U','V','W','X','Y','Z'};
    private static final Object[] AnyChar = { Lowercase, Capitalization, Symbol, Number };

    private static char randomChar(int index){
        char[] currentChar;
        if(index < AnyChar.length){
            currentChar = (char[]) AnyChar[index];
        }
        else{
            currentChar = (char[]) AnyChar[new Random().nextInt(AnyChar.length)];
        }
        int pos = new Random().nextInt(currentChar.length);
        int i = 0;
        for(char c : currentChar){
            if(i++ == pos){
            return c;
            }
        }
        return 0;
    }

    public static String strongDigitGenerate(int len){
        StringBuilder stringBuilder = new StringBuilder();
        for (int i = 0 ; i < len ; i ++){
            stringBuilder.append(randomChar(i));
        }
        return stringBuilder.toString();
    }
}
